package com.four.peoplemanage.exit.dao;

import com.four.peoplemanage.exit.entity.Exit;
import com.four.peoplemanage.overtime.entity.Overtime;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExitDao {
    //申请出境
    @Insert("insert into `exit` (information_id,name,persionstatus,begintime,endtime,cause,look_status,type_abroad,office,degree_confidentiality,passport_number,destination_departure,approval_number,group_units,travel_country,stay_date,travel_abroad,abroad_date,abroad_place,abroad_matter,annex,status)"+
            "values (#{information_id},#{name},#{persionstatus},#{begintime},#{endtime},#{cause},#{look_status},#{type_abroad},#{office},#{degree_confidentiality},#{passport_number},#{destination_departure},#{approval_number},#{group_units},#{travel_country},#{stay_date},#{travel_abroad},#{abroad_date},#{abroad_place},#{abroad_matter},#{annex},#{status})")
    public int addExit(Exit exit);


    //分页查询
    @Select("<script>" +
            "SELECT * FROM `exit`" +
            "  <where>" +
            "    <if test=\"name != null\">" +
            "       `name` = #{name} " +
            "    </if>" +
            "    <if test=\"persionstatus != null\">" +
            "       AND `persionstatus` = #{persionstatus} " +
            "    </if>" +
            "    <if test=\"office != null\">" +
            "       AND `office` = #{office} " +
            "    </if>" +
            "    <if test=\"status != null\">" +
            "       AND `status` = #{status} " +
            "    </if>" +
            "  </where>" +
            "  ORDER BY CASE `status` WHEN '待审核' THEN 1 ELSE 2 END " +
            "LIMIT #{start}, #{size}" +
            "</script>")
    public List<Exit> getExit(int start,  int size,
                               String name,  String persionstatus,
                              String office,  String status);

    //分页查询
    @Select("<script>" +
            "SELECT * FROM `exit`" +
            "  <where>" +
            "    <if test=\"name != null\">" +
            "       `name` = #{name} " +
            "    </if>" +
            "    <if test=\"persionstatus != null\">" +
            "       AND `persionstatus` = #{persionstatus} " +
            "    </if>" +
            "    <if test=\"office != null\">" +
            "       AND `office` = #{office} " +
            "    </if>" +
            "    <if test=\"status != null\">" +
            "       AND `status` = #{status} " +
            "    </if>" +
            "       and information_id=#{information_id}" +
            "  </where>" +
            "  ORDER BY CASE `status` WHEN '待审核' THEN 1 ELSE 2 END " +
            "LIMIT #{start}, #{size}" +
            "</script>")
    public List<Exit> getOneExit(int start,  int size,
                              String name,  String persionstatus,
                              String office, int information_id, String status);

    @Select("<script>" +
            "select count(*) from `exit`" +
            "  <where>" +
            "    <if test=\" name != null\">" +
            "       `name` = #{name} " +
            "    </if>" +
            "    <if test=\" persionstatus != null\">" +
            "       and `persionstatus` = #{persionstatus} " +
            "    </if>" +
            "    <if test=\" office != null\">" +
            "       and `office` = #{office} " +
            "    </if>" +
            "    <if test=\" status != null\">" +
            "       and `status` = #{status} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public  int countExit(String name, String persionstatus,String office,
                              String status);

    //更新
    @Update("<script>" +
            "update  `exit` " +
            "        <set>" +
            "            <if test=\"null!= status\">" +
            "                `status` =#{status}," +
            "            </if>" +
            "            <if test=\"null!= cause\">" +
            "                `cause` =#{cause}," +
            "            </if>" +
            "            <if test=\"null!= travel_abroad\">" +
            "                `travel_abroad` =#{travel_abroad}," +
            "            </if>" +
            "        </set>" +
            "        where `id` =#{id}" +
            "</script>")
    public int updateExitById(Exit exit);

    @Update("<script>" +
            "update  `exit` " +
            "        <set>" +
            "            <if test=\"null!= status\">" +
            "                `status` =#{status}," +
            "            </if>" +
            "        </set>" +
            "        where `id` =#{id}" +
            "</script>")
    public int updateExit(Exit exit);
}
